//
//  DYCommonWebView.m
//  TerritoryShopkeeper
//
//  Created by 黄德玉 on 2018/6/20.
//  Copyright © 2018年 ZDQK. All rights reserved.
//

#import "DYCommonWebView.h"
#import <WebKit/WebKit.h>
#import <Masonry/Masonry.h>

@interface DYCommonWebView ()
@property (nonatomic,strong) WKWebView * webView;
@property (nonatomic,strong) WKUserContentController * contentController;

@end

@implementation DYCommonWebView

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"店铺协议";
    [self.view addSubview:self.webView];
    [self _loadData];
}

- (void)_loadData{
    __weak typeof(self) weakSelf = self;
    [MYAFNetworking POST:@"api2/shopProtocol" parameters:@{} success:^(NSURLSessionDataTask * _Nullable task, id  _Nullable responseObject) {
        [MBProgressHUD hideHUDForView:weakSelf.view animated:YES];
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nullable error) {
        [MBProgressHUD hideHUDForView:weakSelf.view animated:YES];
    }];
}

- (WKWebView *)webView{
    if (!_webView) {
        WKWebViewConfiguration *config = [WKWebViewConfiguration new];
        self.contentController = [[WKUserContentController alloc] init];
        config.userContentController = self.contentController;
        config.preferences = [WKPreferences new];
        config.preferences.minimumFontSize = 10;
        config.preferences.javaScriptEnabled = YES;
        config.preferences.javaScriptCanOpenWindowsAutomatically = NO;
        _webView = [[WKWebView alloc] initWithFrame:self.view.bounds configuration:config];
        _webView.allowsBackForwardNavigationGestures = YES;
        _webView.scrollView.maximumZoomScale = 1.0;
        _webView.scrollView.minimumZoomScale   = 1.0;
        _webView.scrollView.showsHorizontalScrollIndicator = NO;
        _webView.scrollView.showsVerticalScrollIndicator = NO;
    }
    return _webView;
}

@end
